﻿using System;
using System.Linq;

namespace CuteRibs.WowArmory.Models
{
	[AttributeUsage(AttributeTargets.Property)]
	sealed class ItemSlotAttribute : Attribute
	{
		private readonly ItemSlot itemSlot;

		public ItemSlotAttribute(ItemSlot itemSlot)
		{
			this.itemSlot = itemSlot;
		}

		public ItemSlot ItemSlot
		{
			get { return this.itemSlot; }
		}

		public static void SetItemSlot(object obj)
		{
			if (obj == null)
			{
				return;
			}

			foreach (var property in obj.GetType().GetProperties())
			{
				var attribute = property.GetCustomAttributes(typeof(ItemSlotAttribute), false).OfType<ItemSlotAttribute>().FirstOrDefault();

				if (attribute != null)
				{
					var item = property.GetValue(obj, null) as Item;

					if (item != null)
					{
						item.ItemSlot = attribute.ItemSlot;
					}
				}
			}
		}
	}

	public enum ItemSlot
	{
		Head,
		Neck,
		Shoulder,
		Back,
		Chest,
		Tabard,
		Wrist,
		Hands,
		Waist,
		Legs,
		Feet,
		Finger1,
		Finger2,
		Trinket1,
		Trinket2,
		MainHand,
		OffHand,
		Ranged
	}
}
